//
//  WJYNewsTableViewCell.m
//  WWLNetease
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 Echo.Jobs. All rights reserved.
//

#import "WJYNewsTableViewCell.h"

@interface WJYNewsTableViewCell ()

@property (nonatomic, retain) UIImageView *imageV; /**< 图片 */
@property (nonatomic, retain) UILabel *titleL;/**< 条比 */
@property (nonatomic, retain) UILabel *shortIntroL;/**< 简介 */
@property (nonatomic, retain) UILabel *replyL;/**< 跟贴 */
@property (nonatomic, retain) UILabel *tagL;/**< 标识 */

@end

@implementation WJYNewsTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createViews];
    }
    return self;
}

#pragma mark- 重写方法
- (void)createViews
{
    
    // 图片
    self.imageV = [[UIImageView alloc]init];
    [self.contentView addSubview:self.imageV];
    self.imageV.backgroundColor = [UIColor greenColor];
    [self.imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self.contentView.mas_left).offset(10.0);
        make.width.equalTo(@100);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-10);
        
    }];
    
    
    // 标题
    self.titleL = [[UILabel alloc]init];
    [self.contentView addSubview:self.titleL];
    [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imageV.mas_right).offset(10);
        make.top.equalTo(self.imageV).offset(5);
        make.right.equalTo(self.contentView).offset(-5);
        make.height.equalTo(@(15 * SIZE));
        
    }];
    self.titleL.font = [UIFont systemFontOfSize:16.0 * SIZE];
    

    
    // 简介
    self.shortIntroL = [[UILabel alloc]init];
    [self.contentView addSubview:self.shortIntroL];
    [self.shortIntroL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self.titleL);
        make.top.equalTo(self.titleL.mas_bottom).offset(10);
        make.height.equalTo(@(40 * SIZE));
        
    }];
    self.shortIntroL.textColor = [UIColor colorWithWhite:0.620 alpha:1.000];
    self.shortIntroL.numberOfLines = 0;
    self.shortIntroL.font = [UIFont systemFontOfSize:14.0 * SIZE];
    
  
    // 跟贴
    self.replyL = [[UILabel alloc] init];
    [self.contentView addSubview:self.replyL];
    [self.replyL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.shortIntroL).offset(-12);
        make.width.equalTo(@70);
        
#warning 可改进的
        make.top.equalTo(self.shortIntroL.mas_centerY).offset(5);
        make.height.equalTo(@20);
        
    }];
//    self.replyL.layer = 1;
    self.replyL.textAlignment = NSTextAlignmentRight;
    self.replyL.font = [UIFont systemFontOfSize:14.0 * SIZE];
    self.replyL.textColor = [UIColor colorWithWhite:0.620 alpha:1.000];
    
 
    
//    // 标识
//    self.tagL = [[UILabel alloc] initWithFrame:CGRectMake([[UIScreen mainScreen] bounds].size.width - 10 - 30, [[UIScreen mainScreen] bounds].size.height / PART_CELL_HEIGHT - 15 - self.shortIntroL.frame.size.height / 4, 30, self.shortIntroL.frame.size.height / 4)];
//    self.tagL.layer.allowsEdgeAntialiasing =YES;
//    self.tagL.layer.borderWidth = 0.3;
//    self.tagL.layer.borderColor = [UIColor blueColor].CGColor;
//    self.tagL.textAlignment = NSTextAlignmentCenter;
//    self.tagL.font = [UIFont systemFontOfSize:12.0 * KPropotionFont];
//    self.tagL.textColor = [UIColor blueColor];

}

#pragma mark- 传值方法
- (void)setNewsM:(WJYNewsModel *)newsM{

 
    
    
    NSURL *url = [NSURL URLWithString:newsM.imgsrc];
    [self.imageV sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"u=1625671141,2113623839&fm=21&gp=0.jpg"]];
    
    
    self.titleL.text = newsM.title;
    
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineSpacing = 4;
    NSDictionary *attrDict = @{
                                 NSParagraphStyleAttributeName: paraStyle,
                                 NSFontAttributeName: [UIFont systemFontOfSize: 14.0 * SIZE] };
    
    CGFloat height = [AdjustLabelWidthToFitFontAppTools heightForContent:newsM.digest width:self.contentView.frame.size.width - 100 - 10 - 2 fontSize:40 * SIZE];
    CGRect frame = self.shortIntroL.frame;
    frame.size.height = height;
    self.shortIntroL.frame = frame;
    self.shortIntroL.attributedText = [[NSAttributedString alloc] initWithString:newsM.digest attributes: attrDict];
    

    if (newsM.replyCount != nil) {
        if (newsM.replyCount.integerValue >= 10000 ) {
            self.replyL.text = [NSString stringWithFormat:@"%.1ld万跟帖", newsM.replyCount.integerValue / 10000];
        }else{
            self.replyL.text = [NSString stringWithFormat:@"%@跟帖", newsM.replyCount];
        }
    }
    if ([self.newsM.skipType isEqualToString:@"special"])  {
        
        self.replyL.text = @"专题";
        self.replyL.textColor = [UIColor redColor];
                [self.replyL removeFromSuperview];
    }
    
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
